package LinkList;

import java.util.Arrays;
import java.util.Scanner;

public class Stack {
    private int[] elem;
    private int usedSize;

    private static final int DEFAULT = 10;
    public Stack(){
        this.elem = new int[DEFAULT];
    }

    public void push(int val){
        if(this.usedSize >= this.elem.length){
            System.out.println("超过了最大容量了");
            this.elem = Arrays.copyOf(this.elem,2 * this.elem.length);
        }
        this.elem[this.usedSize] = val;
        this.usedSize++;
    }

    public int pop(){
        if(isEmpty()){
            throw new EmptyException();
        }
        int oldval = this.elem[this.usedSize-1];
        this.usedSize--;
        return oldval;
    }


    public int peek(){
        return this.elem[this.usedSize-1];
    }

    public boolean isEmpty(){
        if(this.usedSize== 0){
            return true;
        }
        return false;
    }

}
